<?php
	require_once 'header.php';
	require_once 'navigation.php';
	//init session
	if (! isset($_SESSION['idStr']) || ! isset($_SESSION['numStr'])) {
		$_SESSION['idStr'] = '';
		$_SESSION['numStr'] = '';
	}
	
	//query product info
	$arrayIds = explode('@', $_SESSION['idStr']);
	$arrayNums = explode('@', $_SESSION['numStr']);
	$arrayCarInfos = array();
	$totalPrice = 0;
	for ($i = 0; $i < count($arrayIds); $i ++) {
		$productid = $arrayIds[$i];
		if ($productid != '') {
			$tmpArray = array();
			$productinfo = $adminDB->executeSQL("select id, fdName,fdLicense,fdPrice,fdVersion from ".$util->contentdbName().".tbProduct where id = ".$productid."", $connID);
			$tmpArray['id'] = $productinfo[0]['id'];
			$tmpArray['name'] = $productinfo[0]['fdName'];
			$tmpArray['version'] = $productinfo[0]['fdVersion'];
			$tmpArray['license'] = $productinfo[0]['fdLicense'];
			$tmpArray['price'] = $productinfo[0]['fdPrice'];
			$tmpArray['num'] = $arrayNums[$i];
			$tmpArray['smallTotalPrice'] = $productinfo[0]['fdPrice'] * $arrayNums[$i];
			$totalPrice += $tmpArray['smallTotalPrice'];
			array_push($arrayCarInfos, $tmpArray);
		}
	}
	$smarty->assign('arrayCarInfos', $arrayCarInfos);
	$smarty->assign('totalPrice', $totalPrice);
	//validate login
	if (isset($_SESSION['unc']) && $_SESSION['unc'] != '') {
		$smarty->assign('isLogin', 'T');
		
		$usernc = $_SESSION['unc'];
		$user = $adminDB->executeSQL("select u.id, u.fdName, u.fdCompany, u.fdPosition, e.fdEmail, t.fdPhone as fdTelePhone, m.fdPhone as fdMobilePhone, a.fdAddress from ".$util->userdbName().".tbUser u left outer join ".$util->userdbName().".tbEmail e on e.fdUserID=u.id and e.fdDefault=0 left outer join ".$util->userdbName().".tbPhone t on t.fdUserID=u.id and t.fdTypeID=0 left outer join ".$util->userdbName().".tbPhone m on m.fdUserID=u.id and m.fdTypeID=1 left outer join ".$util->userdbName().".tbAddress a on a.fdUserID=u.id and a.fdDefault=0 where u.fdLogin='".$usernc."'", $connID);
		
		$smarty->assign('user', $user);
		
	} else {
		$smarty->assign('isLogin', 'F');
		if (isset($_SESSION['toUrl'])) {
			unset($_SESSION['toUrl']);
		}
		$_SESSION['toUrl'] = 'confirm.php';
		
	}
	
	$smarty->display('confirm.html');
	require_once 'footer.php';
?>